#include "StdAfx.h"
#include "TestActiveInterface.h"

// Includes for factory method.
#include "TestActiveObject.h"

namespace CO { namespace SpiFoundation { namespace RoomFW {

//
// TODO: Implement factory method to create derived type objects.
//
TestActiveInterfaceSP TestActiveInterface::Create()
{
	return TestActiveObjectSP(new TestActiveObject());
}

//
// TODO:  Add priority for each port in order declared, including timer.
//
const SpiFoundation::RoomFW::ActiveObject::PortPriority TestActiveInterface::PortPriorities[] = {
	PRI_HIGH,	// PORT_SYSTEM
	PRI_NORMAL,	// PORT_MY_PORT_1
	PRI_NORMAL,	// PORT_MY_PORT_2
	PRI_NORMAL,	// PORT_MY_PORT_3
	PRI_NORMAL,	// PORT_MY_PORT_4
	PRI_HIGH	// PORT_TIMER
};
const size_t TestActiveInterface::PortPrioritiesSize = sizeof(TestActiveInterface::PortPriorities) / sizeof(IActiveObject::PortPriority);
BOOST_STATIC_ASSERT(TestActiveInterface::PortPrioritiesSize == TestActiveInterface::PORT_COUNT + 1);

TestActiveInterface::TestActiveInterface(void) :
	//
	// TODO:  Initialize protocol attributes.
	//
	systemProtocol_(true),
	inProtocol_(false),
	outProtocol_(true)
{
}

TestActiveInterface::~TestActiveInterface(void)
{
}

const char* TestActiveInterface::getPortName(size_t portIndex) const
{
	//
	// TODO:  Add text for each port name for debugging.
	//
	const char* retVal = "***UNKNOWN***";
	switch (portIndex)
	{
	case PORT_SYSTEM:
		retVal = "PORT_SYSTEM";
		break;
	case PORT_MY_PORT_1:
		retVal = "PORT_MY_PORT_1";
		break;
	case PORT_MY_PORT_2:
		retVal = "PORT_MY_PORT_2";
		break;
	case PORT_MY_PORT_3:
		retVal = "PORT_MY_PORT_3";
		break;
	case PORT_MY_PORT_4:
		retVal = "PORT_MY_PORT_4";
		break;
	case PORT_TIMER:
		retVal = "PORT_TIMER";
		break;
	default:
		ASSERT(false); // Invalid port.
	};
	return retVal;
}

SpiFoundation::RoomFW::IContractCheckerSPC
TestActiveInterface::getContractChecker(SpiFoundation::RoomFW::PortIndex portIndex) const
{
	//
	// TODO:  Return the contract checker for each port.
	//
	SpiFoundation::RoomFW::IContractCheckerSPC retVal;
	switch (portIndex.port())
	{
	case PORT_SYSTEM:
		retVal = SpiFoundation::RoomFW::IContractCheckerSPC(&systemProtocol_, SpiControl::Protocol::SystemManagerProtocolNullDeleter());
		break;
	case PORT_MY_PORT_1:
		retVal = SpiFoundation::RoomFW::IContractCheckerSPC(&inProtocol_, GenericTestProtocolNullDeleter());
		break;
	case PORT_MY_PORT_2:
		retVal = SpiFoundation::RoomFW::IContractCheckerSPC(&inProtocol_, GenericTestProtocolNullDeleter());
		break;
	case PORT_MY_PORT_3:
		retVal = SpiFoundation::RoomFW::IContractCheckerSPC(&outProtocol_, GenericTestProtocolNullDeleter());
		break;
	case PORT_MY_PORT_4:
		retVal = SpiFoundation::RoomFW::IContractCheckerSPC(&outProtocol_, GenericTestProtocolNullDeleter());
		break;
	default:
		ASSERT(false); // Invalid port.
	}
	return retVal;
}

}}} // End namespace
